home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* MCPlayMovie. */
- /* by John Wang */
- /* */
- /* Description: This program demonstrates playing movies with */
- /* QuickTime movie controllers. It also allows the user to save */
- /* the movies in a flattened format using FlattenMovie(). */
- /* */
- /* Version: 1.0 Completed 11/17/91 */
- /* 1.1 Added palette support so that app restores */
- /* color table when changed by another app. */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <GestaltEqu.h>
- #include <Palette.h>
- #include "PlayMovie.h"
-
-
- /*------------------------------------------------------*/
- /* Global Variables. */
- /*------------------------------------------------------*/
-
- extern short quitFlag;
- MenuHandle mymenu0, mymenu1;
- Boolean playingMovie[MAXWINDOWS];
- WindowPtr myWindow[MAXWINDOWS];
- Movie myMovie[MAXWINDOWS];
- MovieController mcPlay[MAXWINDOWS];
- int startlocation;
- CTabHandle mycolors;
- PaletteHandle srcPalette;
-
- /*------------------------------------------------------*/
- /* getMovieFromFile(). */
- /*------------------------------------------------------*/
-
- Movie getMovieFromFile(void)
- {
- OSErr err;
- StandardFileReply reply;
- Point where = {200, 50};
- SFTypeList types;
- short movieResRefNum;
- short actualResId;
- Movie theMovie;
-
- types[0] = 'MooV';
- StandardGetFilePreview(nil, 1, types, &reply);
- if (!reply.sfGood) return((Movie) 0);
-
- err = OpenMovieFile(&reply.sfFile, &movieResRefNum, fsRdPerm);
- if (GetMoviesError()) return((Movie) 0);
- if (err) return ((Movie) 0);
- actualResId = DoTheRightThing;
-
- err = NewMovieFromFile(&theMovie, movieResRefNum, &actualResId, 0L, newMovieActive, (Boolean *) 0);
- if (GetMoviesError()) return((Movie) 0);
- if (err) return ((Movie) 0);
-
- err = CloseMovieFile(movieResRefNum);
- if (GetMoviesError()) return((Movie) 0);
- if (err) return ((Movie) 0);
-
- return (theMovie);
- }
-
- /*------------------------------------------------------*/
- /* playMovie(). */
- /*------------------------------------------------------*/
-
- OSErr playMovie(int index)
- {
- Rect movieBounds;
- Str255 windTitle;
-
- GetMovieBox(myMovie[index], &movieBounds);
- OffsetRect(&movieBounds, -movieBounds.left, -movieBounds.top);
- /* movieBounds.right = movieBounds.right * 2;
- movieBounds.bottom = movieBounds.bottom * 2; */
- SetMovieBox(myMovie[index], &movieBounds);
- OffsetRect(&movieBounds, startlocation, startlocation);
-
-
- NumToString (index, windTitle);
- myWindow[index] = NewCWindow(0L, &movieBounds, windTitle, 1, 0, (WindowPtr) -1, FALSE, 0L);
- SetPalette ((WindowPtr) myWindow[index], srcPalette, TRUE);
-
- OffsetRect(&movieBounds, -startlocation, -startlocation);
- startlocation += 40;
- if (startlocation > 300) startlocation = 50;
-
- SetMovieGWorld(myMovie[index], (CGrafPtr) myWindow[index], 0);
- if (GetMoviesError()) DebugStr("\PSetMovieGWorld error.");;
- mcPlay[index] = NewMovieController(myMovie[index], &movieBounds, mcTopLeftMovie);
- MCGetControllerBoundsRect(mcPlay[index], &movieBounds);
- SizeWindow(myWindow[index], movieBounds.right - movieBounds.left,
- movieBounds.bottom - movieBounds.top, TRUE);
- /* Uncomment these lines if you want to pre load the movie into ram.
- Don't forget to increase the partition size when recompiling.
-
- GotoBeginningOfMovie(myMovie[index]);
- if (LoadMovieIntoRam(myMovie[index], GetMovieTime(myMovie[index], 0L),
- GetMovieDuration(myMovie[index]),
- 0) != noErr)
- DebugStr("\PNot enough memory to load movie into ram.");
- */
- }
-
-
- /*------------------------------------------------------*/
- /* init(). */
- /*------------------------------------------------------*/
-
- void InitPlayMovie(void)
- {
- OSErr err;
- int i;
- long QDfeature, OSfeature;
-
- /* Set up menus. */
- mymenu0 = GetMenu(appleID);
- AddResMenu(mymenu0, 'DRVR');
- InsertMenu(mymenu0,0);
- mymenu1 = GetMenu(fileID);
- InsertMenu(mymenu1,0);
- DrawMenuBar();
-
- /* Set up variables. */
- startlocation = 50;
- for (i = 0; i < MAXWINDOWS; i++) {
- playingMovie[i] = FALSE;
- myWindow[i] = nil;
- }
- mycolors = GetCTable (72);
- if (mycolors == nil) Debugger();
- srcPalette = NewPalette (((**mycolors).ctSize)+1, mycolors, pmTolerant, 0);
-
- /* Use Gestalt to find if QuickDraw and QuickTime is available. */
- if ((GetTrapAddress(Gestalttest) != GetTrapAddress(NoTrap))) {
- err = Gestalt(gestaltQuickdrawVersion, &QDfeature);
- if (err)
- ExitToShell();
- err = Gestalt(gestaltSystemVersion, &OSfeature);
- if (err)
- ExitToShell();
- if (!quitFlag && (QDfeature & 0x0f00) != 0x0200 && OSfeature < 0x0607)
- ExitToShell();
- err = Gestalt(gestaltQuickTime, &QDfeature);
- if (err)
- ExitToShell();
- } else
- ExitToShell();
-
- /* Open QuickTime last. */
- err = EnterMovies();
- if (err)
- ExitToShell();
- }
-
- /*------------------------------------------------------*/
- /* ClosePlayMovie(). */
- /*------------------------------------------------------*/
-
- void ClosePlayMovie(void)
- {
- int i;
-
- for (i = 0; i < MAXWINDOWS; i++)
- if (playingMovie[i] == TRUE) {
- CloseComponent(mcPlay[i]);
- DisposeMovie(myMovie[i]);
- DisposeWindow(myWindow[i]);
- playingMovie[i] = FALSE;
- }
-
- ExitMovies();
- ExitToShell();
- }
-
- /*------------------------------------------------------*/
- /* doOpenCommand(). */
- /*------------------------------------------------------*/
-
- void doOpenCommand()
- {
- int i, useThisIndex;
-
- useThisIndex = -1;
-
- /* Search for the first window that is nil. */
- for (i = MAXWINDOWS-1; i >= 0; i--)
- if (myWindow[i] == nil)
- useThisIndex = i;
-
- /* If index = -1, then it means that there are no windows avaiable. */
- if (useThisIndex != -1) {
- myMovie[useThisIndex] = getMovieFromFile();
- if (myMovie[useThisIndex] != 0) {
- playMovie(useThisIndex);
- playingMovie[useThisIndex] = TRUE;
- }
- }
- }
-
-
- /*------------------------------------------------------*/
- /* doCloseCommand(). */
- /*------------------------------------------------------*/
-
- void doCloseCommand()
- {
- int i, useThisIndex;
- WindowPtr myTempWindow;
-
- /* Close selected window. */
- myTempWindow = FrontWindow();
- if (myTempWindow == nil) return;
- for (i = 0; i < MAXWINDOWS; i++)
- if (myWindow[i] == myTempWindow) {
- CloseComponent(mcPlay[i]);
- DisposeMovie(myMovie[i]);
- DisposeWindow(myTempWindow);
- playingMovie[i] = FALSE;
- myWindow[i] = nil;
- }
- }
-
- /*------------------------------------------------------*/
- /* doCommand(). */
- /*------------------------------------------------------*/
-
- void doCommand(long mResult)
- {
- int theMenu, theItem;
- char daName[256];
- GrafPtr savePort;
-
- theItem = LoWord(mResult);
- theMenu = HiWord(mResult);
-
- switch (theMenu) {
- case appleID:
- if (theItem == aboutMeCommand)
- ;
- else {
- GetItem(mymenu0, theItem, daName);
- GetPort(&savePort);
- (void) OpenDeskAcc(daName);
- SetPort(savePort);
- }
- break;
-
- case fileID:
- switch (theItem) {
- case openCommand:
- doOpenCommand();
- break;
- case closeCommand:
- doCloseCommand();
- break;
- case quitCommand:
- quitFlag = TRUE;
- break;
- default:
- break;
- }
- break;
- }
- HiliteMenu(0);
- return;
- }
-
- /*------------------------------------------------------*/
- /* playMovies(). */
- /*------------------------------------------------------*/
-
- int playMovies(EventRecord *myEvent)
- {
- int i;
-
- for (i = 0; i < MAXWINDOWS; i++)
- if (playingMovie[i] == TRUE) {
- if (MCIsPlayerEvent(mcPlay[i], myEvent))
- return(TRUE);
- }
- return(FALSE);
- }
-
- void
- BringToMooVFront(short frontBack) {
- int i;
- int cnt;
-
- for (i = 0; i < MAXWINDOWS; i++)
- if (myWindow[i] == FrontWindow()) {
- cnt = i;
- }
- if (frontBack) {
- for (i = cnt+1; i < MAXWINDOWS; i++)
- if (myWindow[i]) {
- SelectWindow(myWindow[i]);
- return;
- }
- for (i = 0; i < cnt; i++)
- if (myWindow[i]) {
- SelectWindow(myWindow[i]);
- return;
- }
- }
- else {
- for (i = cnt-1; i >= 0; i--)
- if (myWindow[i]) {
- SelectWindow(myWindow[i]);
- return;
- }
- for (i = MAXWINDOWS - 1; i > cnt; i--)
- if (myWindow[i]) {
- SelectWindow(myWindow[i]);
- return;
- }
-
- }
-
- }
-
- void IRMooVPlay(long Speed) {
- short i;
- short cnt = -1;
- long forward;
-
- for (i = 0; i < MAXWINDOWS; i++)
- if (myWindow[i] == FrontWindow()) {
- cnt = i;
- }
- if (cnt != -1) {
- forward = Speed;
- MCDoAction(mcPlay[cnt], mcActionPlay, (Ptr)forward);
- }
- }
-
- void IRMooVStep(long Speed) {
- short i;
- short cnt = -1;
- long forward;
-
- for (i = 0; i < MAXWINDOWS; i++)
- if (myWindow[i] == FrontWindow()) {
- cnt = i;
- }
- if (cnt != -1) {
- forward = Speed;
- MCDoAction(mcPlay[cnt], mcActionStep, (Ptr)forward);
- }
- }
-
- void IRMooVVolume(short Speed) {
- short i;
- short cnt = -1;
- short vol;
-
- for (i = 0; i < MAXWINDOWS; i++)
- if (myWindow[i] == FrontWindow()) {
- cnt = i;
- }
- if (cnt != -1) {
- MCDoAction(mcPlay[cnt], mcActionGetVolume, &vol);
- if (Speed)
- vol = vol + 25;
- else
- vol = vol - 25;
- if (vol < 0)
- vol = 0;
- if (vol > 255)
- vol = 255;
-
- MCDoAction(mcPlay[cnt], mcActionSetVolume, (Ptr)vol);
- }
- }
-
-
- void doAboutBox()
- {
- int i, useThisIndex;
-
- useThisIndex = -1;
-
- /* Search for the first window that is nil. */
- for (i = MAXWINDOWS-1; i >= 0; i--)
- if (myWindow[i] == nil)
- useThisIndex = i;
-
- /* If index = -1, then it means that there are no windows avaiable. */
- if (useThisIndex != -1) {
- myMovie[useThisIndex] = getMovieFromFile();
- if (myMovie[useThisIndex] != 0) {
- playMovie(useThisIndex);
- playingMovie[useThisIndex] = TRUE;
- }
- }
- }
-
-
- Movie LoadAboutBox(void)
- {
- OSErr err;
- StandardFileReply reply;
- Point where = {200, 50};
- SFTypeList types;
- short movieResRefNum;
- short actualResId;
- Movie theMovie;
-
- reply.sfFile.vRefNum = 1;
- reply.sfFile.parID = 0;
- BlockMove("\pAbout Box Movie", reply.sfFile.name, 16);
-
- err = OpenMovieFile(&reply.sfFile, &movieResRefNum, fsRdPerm);
- if (GetMoviesError()) return((Movie) 0);
- if (err) return ((Movie) 0);
- actualResId = DoTheRightThing;
-
- err = NewMovieFromFile(&theMovie, movieResRefNum, &actualResId, 0L, newMovieActive, (Boolean *) 0);
- if (GetMoviesError()) return((Movie) 0);
- if (err) return ((Movie) 0);
-
- err = CloseMovieFile(movieResRefNum);
- if (GetMoviesError()) return((Movie) 0);
- if (err) return ((Movie) 0);
-
- return (theMovie);
- }
-